package com.yq.bdm.listener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.yq.bdm.entity.SysParamsDictEntity;
import com.yq.bdm.service.SysParamsDictService;
import com.yq.bdm.utils.SysParamsConstants;

public class SysParamsDictInitListener implements ApplicationListener<ContextRefreshedEvent> {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private SysParamsDictService sysParamsDictService;
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent evt) {
		// 防止启动两次
		if (evt.getApplicationContext().getParent() != null) {
			buildIndex();
		}
	}

	private void buildIndex() {
		logger.info("********************数据字典初始化********************");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("prmStatus", 0);
		List<SysParamsDictEntity> dicts = sysParamsDictService.queryList(null);
		for(SysParamsDictEntity entity : dicts){
			switch(entity.getPrmName()) {
				case "NAMESPACEURL" : 
					SysParamsConstants.NAMESPACEURL = entity.getPrmValue();
					break;
				default: break;  
			}
		}
	}
}
